package JDBC;

import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCUtil {
    private static Connection conn=null;
    public static Connection getCon(){
        return conn;
    }
static{
    try{
        Class.forName("com.mysql.jdbc.Driver");
         conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","root","123");
        System.out.println(conn);
    }catch(Exception e){
//        e.printStackTrace();
        throw new RuntimeException(e+"连接数据库失败");

    }
}
/*关闭释放资源*/
public static void close(){
    if(conn!=null){
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

}
